package com.shruijin.wy.thread.notify;

import com.shruijin.wy.thread.signal.Signal;

public class ThreadNotify {

    private Signal signal = new Signal();
    private boolean wassigned = false;

    public  boolean hasLock(){
        return signal.isHasLock();
    }

    public  void setLock(boolean val){
        signal.setHasLock(val);
    }

    public void dowait() throws InterruptedException {
        synchronized (signal){
            while (!wassigned){//添加自旋锁
                signal.wait();
            }
            wassigned=false;
        }
    }

    public void donotify(){
        synchronized (signal){
            wassigned=true;
            signal.notify();
        }
    }

}
